package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogActivityDispGoldClientResult;
import com.yanqu.road.entity.log.LogActivityDisperseGold;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogActivityDisperseGoldDaoImpl extends TempDao {

    public boolean addLogActivityDisperseGoldLog(List<LogActivityDisperseGold> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_disperse_gold_log(userId,activityId,logTime)"
                + " VALUES(?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogActivityDisperseGold data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogActivityDispGoldClientResult(List<LogActivityDispGoldClientResult> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_disp_gold_client_result(disperseId,userId,activityId,activityType,resultType,actionTime,reward,logTime) VALUES(?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogActivityDispGoldClientResult data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getDisperseId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getActivityType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getResultType()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getActionTime())));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getLogTime())));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
